// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/silicon_creator/lib/sigverify/sphincsplus/verify.h"
#include "sw/device/silicon_creator/lib/sigverify/spx_verify.h"

/**
 * Generated using:
 *
 * ```
 * # Private key (not used, for reference only)
 * opentitantool spx key generate <OUTPUT_DIR> test_key
 * cat test_key.pem | tail -n +2 | head -n -1 | base64 -d | \
 *     hexdump -v -e '/4 "0x%08x, \n"'
 * # Public key
 * cat test_key.pub.pem | tail -n +2 | head -n -1 | base64 -d | \
 *     hexdump -v -e '/4 "0x%08x, \n"'
 * # Signature
 * echo -n "test message" > test_message
 * opentitantool spx sign -o signature test_message test_key.pem
 * cat signature | hexdump -v -e '/4 "0x%08x, \n"'
 * ```
 */
static const char kMessage[] = "test message";
static const size_t kMessageLen = sizeof(kMessage) - 1;
static const uint32_t kPrivKey[] = {
    0xf54ec8c7, 0x31112318, 0xef4eb42d, 0xb33a8bed, 0x48353913, 0x2ebafb0e,
    0x8194c228, 0x603a35a9, 0xa23b5d15, 0x4db20189, 0xa240ce5a, 0x85b9169e,
    0x7679c7b8, 0xf73998fc, 0xd2c1b3d2, 0xcd9108e3, 0xf54ec8c7, 0x31112318,
    0xef4eb42d, 0xb33a8bed, 0x48353913, 0x2ebafb0e, 0x8194c228, 0x603a35a9,
};
static const sigverify_spx_key_t kPubKey = {
    .data =
        {
            0xf54ec8c7,
            0x31112318,
            0xef4eb42d,
            0xb33a8bed,
            0x48353913,
            0x2ebafb0e,
            0x8194c228,
            0x603a35a9,
        },
};
static sigverify_spx_signature_t kSignature = {
    .data = {
        0x869eff7d, 0x7c7f52ca, 0xd900ccee, 0x8ea0b717, 0x12150170, 0x01ec6688,
        0x6af5c0d3, 0x33ad19f0, 0x9429b8c6, 0x75e32d9a, 0x1d37436b, 0xbb57ddfb,
        0xc13de2c6, 0x28a0e4f9, 0x5f0c7483, 0x88725ff1, 0x8b90e1ee, 0xbaea34f1,
        0x18b9ccd0, 0x8a71a16e, 0x025f52cd, 0x760949fa, 0x4e18f80f, 0x38d69eb7,
        0xac0987de, 0xd131a78c, 0x35ed2cd3, 0x17dc56a4, 0x6e22ef33, 0xea2a9d27,
        0xe0490bbe, 0x57163228, 0xe90766d4, 0x023ea16e, 0xaac8893c, 0xf32ee26a,
        0xdd0d2660, 0x8465f977, 0x3096c82f, 0xb8193f3b, 0x0efdf54c, 0xb0611799,
        0x02ceb414, 0x8dfe9bd0, 0x51c36f42, 0xeb4e664e, 0x3ce2c8a7, 0xdc88c8e7,
        0xec0fc362, 0xf0b08eb5, 0x798517c0, 0x445c7afa, 0xfa5da126, 0x68d10a21,
        0xe59ebf49, 0x00a161e7, 0xce0631d7, 0xac0b94c1, 0xfe864019, 0x1f34844a,
        0xa47f1d9a, 0xd59e869b, 0x61ba1bac, 0x7fc031aa, 0x1c788047, 0x0626bf96,
        0x19633ef8, 0x4a7de09c, 0x097b4414, 0x2d0922b9, 0x08f34c87, 0xff7e7df3,
        0x9372ff46, 0x8fcaa9c6, 0x16bd3c55, 0x6b946042, 0x19203647, 0xb8d813f7,
        0xa1bb2f7e, 0xf010be1d, 0xa93d06c6, 0x4725cb47, 0x21a4f8e3, 0x8e5f464b,
        0x86b1d736, 0x3841d2ce, 0xbeb2b144, 0x1047ea51, 0xffb17be9, 0xb404aa1f,
        0xc05b366a, 0xade9adac, 0x58168ed8, 0x29a604bf, 0xe5d7e884, 0x3f8c114a,
        0xa36c8226, 0xc5b1d1c2, 0x24b672a9, 0xcf3a5db5, 0x08e2bf94, 0x7fe505b0,
        0x8a791047, 0x40f2c26c, 0x7adc1fe1, 0x3799035c, 0x4d388562, 0xb5075093,
        0x4a345eaa, 0x39081d34, 0xd596eb2e, 0x8f8a6dbf, 0xe57d1c7f, 0x9e6635a5,
        0x328ae54c, 0x41ff990c, 0x6878e543, 0x374cf261, 0x60b5eaef, 0xf5b43512,
        0x4fc636ed, 0x51b98fe6, 0x9d460295, 0x03796ecf, 0xca8cd615, 0x16477d58,
        0x8844c380, 0xb0b1df6b, 0x1fef3284, 0x569043f6, 0xd0b61d47, 0x8bceaedd,
        0x54ccc0e2, 0xdd4b8656, 0xd8b6c2d3, 0x08873801, 0x3108afd5, 0x068bc450,
        0x35e11db2, 0xb0201be5, 0x2c346868, 0xead8b8d9, 0xc74f84d6, 0x98a0a9ca,
        0x1990e619, 0x7bee850c, 0xc86d645b, 0xcbdf93d0, 0xd48f987b, 0x1b96b02e,
        0x1f79863e, 0xc9669046, 0x3deecb95, 0x308ce80d, 0xce96cfc6, 0x33622777,
        0xfbc59607, 0x503fcc32, 0x44c3a262, 0x1da89ac4, 0x1e0b01bb, 0x55febab9,
        0x5a768392, 0x4ee75792, 0xf229294d, 0xfdfd5d38, 0x61d9cabb, 0x907d4121,
        0xe03ca22e, 0x005ea68f, 0x80a3142d, 0xa2b8b775, 0xe878679a, 0x03d27bb5,
        0xa6ed3bf8, 0x9114fc43, 0x79da47c0, 0x1f86eb4b, 0xd5a3ba4a, 0x0991e078,
        0x6eeb4be3, 0x194de504, 0x4bc7ae4c, 0x9103d77a, 0x17ca72c0, 0x8aee5b81,
        0x6a780408, 0xa0df0a20, 0xc4896c94, 0x2dc447e2, 0xd859287b, 0x731a9be2,
        0xb70aba07, 0x6fca07dc, 0xf9f9a1e5, 0x32e9f180, 0x71abe7f3, 0xa1d86fd2,
        0xf412d821, 0xab5865e0, 0x3bcb9497, 0x72630aa5, 0xa7678822, 0x04eb47c0,
        0xe1951915, 0x60aeb38a, 0x28dcb11f, 0xbe1921f4, 0xe1c0404b, 0xb07a5b9f,
        0x8a7d9fd0, 0x4c53903c, 0xe4b2b619, 0x10a321a0, 0x54af925e, 0xb462d640,
        0x275bbf83, 0xeb617967, 0xd0afb3d1, 0x2f4be408, 0x046d2ec2, 0x6974abb3,
        0x0d300635, 0x6ab71492, 0xde1e4082, 0xa2a1a5db, 0x40bcaba5, 0x5bb397c7,
        0x47b431b1, 0x9974e53d, 0x2a6b7e30, 0x1c808ae9, 0x443d97cb, 0x6e71749f,
        0xf507b4f0, 0x31bf5591, 0xbb5c3bdc, 0xcba21a45, 0x029df423, 0x8c8ced75,
        0x9c2be3ed, 0x37e04b78, 0xa8829f79, 0x02f71901, 0x74c2693a, 0xfb5224c8,
        0x0acd01b6, 0xfacef64e, 0xb3700b3c, 0xee5f7f24, 0x4869f59c, 0x6d928682,
        0xe3472302, 0x9e16f08c, 0xfc9b4983, 0xd1ed7b00, 0xe607225f, 0x87603a2e,
        0x69efbd15, 0x71b90ce5, 0xae8a32c9, 0xa0448a5a, 0x3c9a9ab2, 0xc55d5ffe,
        0xbba6ec1d, 0x76803c10, 0x0b5066bb, 0x2ab6773c, 0x5c558a3a, 0x99b37685,
        0xb7d40844, 0xc90b412a, 0x770054e5, 0x0693b91e, 0xe741cc39, 0x55239700,
        0x7ed0e5a3, 0xc520b006, 0x58f4383c, 0x5aa8ad8a, 0x64081b40, 0x1ae003b7,
        0x49217a08, 0xee59bc10, 0x7ca391bc, 0x006a0e4d, 0x46ee8bef, 0xcad82ad6,
        0x5444189d, 0x10cfccf5, 0x5ee9c280, 0xa3e109ae, 0x24dc2cc5, 0x27cb56b8,
        0xe159ebba, 0x12994d83, 0x8640e28e, 0x3ffdda05, 0x2fa07e3e, 0x51ed7f86,
        0x0486eb76, 0xb466dcab, 0x077543e6, 0x18286cf3, 0x8b6bf294, 0xa045f9b1,
        0x2b7cbc5e, 0x77142b64, 0xcb2bb933, 0x870095b7, 0xc0f2925a, 0xbecb5351,
        0x5cc3dc50, 0x87c58656, 0xb94d14e7, 0xf660ac25, 0xa4d96e7e, 0x96598b2b,
        0xe16431e0, 0xf471774e, 0x51dfd993, 0xfd97615e, 0xcb2284bd, 0x1b8fe34b,
        0x4b2f2961, 0xeb15ec04, 0x62731463, 0xb3c1507b, 0xe9c2c13b, 0xec9c4aec,
        0x6eb6f769, 0x9ef0e729, 0xabbb78ae, 0x1c9ddded, 0x60713fb1, 0x1a1fdc75,
        0xf9637636, 0x75467d90, 0x5ca2e24f, 0x4863371d, 0x1888c199, 0xd4cbdb0f,
        0x4ad5303e, 0x4a3aa828, 0x5bb41066, 0x20e5ebe3, 0xec6468d4, 0x8516aa05,
        0xb1f1316f, 0xdeaaaf06, 0x96856dfc, 0x73cea67a, 0xa9f34bfb, 0xf445b772,
        0x2a5177b5, 0x2557ff8c, 0x7cfa4cb5, 0xd3453de3, 0x87acf7b2, 0x20cfc76a,
        0x9ddf5744, 0x4da8c64f, 0x4386a249, 0x38eb2bbb, 0x05b7a48d, 0x20600eef,
        0x6ef2f0d6, 0xb3720673, 0x65a920ef, 0xc527fc1f, 0xe4e48d6b, 0x8273136f,
        0x02c5ad82, 0x6d6bc7e2, 0xb6903a96, 0x11cb985d, 0x1ec8debd, 0xf9042c62,
        0xfdfc3513, 0xb950cfef, 0xb97dba8e, 0x1d2318d0, 0xbab32b1b, 0xc5116c81,
        0x126f019a, 0x76a48038, 0x12be70e4, 0x7bc6ee26, 0x9be09044, 0x201a4cac,
        0x97140e47, 0x4e37073b, 0x4e4ed830, 0x03399a53, 0xcc2d81d6, 0x3cc25359,
        0x5301f88a, 0xa3362256, 0x5a113e36, 0x2dc86d7c, 0x99a38cfa, 0x9b65c10d,
        0xc172e20f, 0xe65a747a, 0x437ea6d9, 0x6fb8c2d5, 0x1d70f1ab, 0x4a3534f2,
        0x39feaea5, 0xef448d6a, 0xacc2fc5e, 0xf03704a1, 0xda45fb92, 0x78187955,
        0x3fd2af26, 0x08f4e5de, 0xcc4999ba, 0x1c126004, 0x3d644824, 0x46d602fc,
        0xfc907eb3, 0x5a7c5a7b, 0x2fc20b46, 0x9d5b97f0, 0x248e8b64, 0xc6fcf285,
        0xe48006ef, 0x7c1746f4, 0xeaf4be1b, 0x89a15c82, 0x0c272be1, 0x6cba6809,
        0x99cc7a37, 0x33381528, 0xf1d36134, 0xf1318511, 0x3c178b8f, 0x2ec0d616,
        0x4107bdd0, 0x225b8d3d, 0x1f2a461f, 0x1052a278, 0xabfb5809, 0xd8d919d1,
        0xb17b1e4b, 0x0a0bd7df, 0x811917a1, 0xe0064e42, 0xa3ed683a, 0xfa5fe074,
        0xb6e0cadd, 0x30311081, 0xa11edff0, 0xa4a36709, 0x52e0ea84, 0xe5ce1b05,
        0x58b87dfd, 0x90643bd0, 0x004452b0, 0xa7106336, 0xd3ef6ea0, 0xef66a4b9,
        0x686d9851, 0x244d8cd3, 0xa67228af, 0xf1821ec3, 0xd17c19ba, 0xba80f706,
        0x97da9711, 0xe4921cab, 0x62355267, 0xd6750285, 0x5fa6af4e, 0xaa5ff99d,
        0x40eb4792, 0xb432cf77, 0xa79c47ef, 0x5ae36cf5, 0x412a79b7, 0xc46ad360,
        0x2fe9885c, 0x83b7cd68, 0xbc717a40, 0x28b34008, 0x15392744, 0x412f0068,
        0xc317c096, 0xaa5f2217, 0x982e7502, 0x12cbe593, 0x0bf5205b, 0xf1046c86,
        0xb304b189, 0xeff73dae, 0x5e46b357, 0xd01c0225, 0x27d50303, 0xc97df07d,
        0x62a15e7b, 0x5a54ed21, 0xfda7cf2c, 0xd98dd67d, 0x716b74ef, 0x8cd1d74e,
        0xafd98ce4, 0xb3a31f23, 0xba2e8af0, 0xb4f6cb45, 0xeaa4ba33, 0x30204fdd,
        0xc0d16614, 0x059b7e37, 0x2f563cd7, 0x2b68f97e, 0x7091b164, 0xd58762b7,
        0x663bcc1b, 0x7c39e10a, 0x24f513da, 0x341af293, 0xca9124ae, 0x98724a56,
        0x9eaafaeb, 0x71373430, 0xab5c5379, 0xd4c86495, 0x76e4851f, 0x662a5221,
        0xf62102d0, 0xa4fabacd, 0x362432be, 0xecbecbfd, 0xbf276088, 0xfd446b0d,
        0xe6120673, 0xe972ccf9, 0xb4d6d606, 0x62bb0c7b, 0x456863df, 0x47171e17,
        0xffbad8e3, 0x04b0f4f5, 0x7835f18b, 0x617d8850, 0xe5b1978e, 0x01c71f14,
        0x088e97e8, 0xdaf06c7e, 0xd10c0863, 0x0c926779, 0x0f5e016a, 0x8c3eab3b,
        0xb9f6971e, 0xd016a637, 0x85853b81, 0xa5d715dc, 0xe683658b, 0x7c530694,
        0x0168ee76, 0x64c514ab, 0xfca5f130, 0xbbfc5cad, 0xfea5bbd4, 0x98fa1204,
        0xa07b3c4f, 0xa802c234, 0x183cf416, 0x9daa86d6, 0x6aea3de6, 0x039ba283,
        0xcea48593, 0xbf9ac83b, 0x609e1a4c, 0x3b7067d7, 0x9d085932, 0x05977b35,
        0xe92ad466, 0x96d559c1, 0xf0cf2983, 0xe332bcfe, 0x655c5951, 0xcd34d040,
        0x5b7905bb, 0x0a3ef093, 0xfb1b4b5d, 0x78454443, 0xe9f5ab71, 0x08bb3ce8,
        0x34e7c5fa, 0x0ff3773c, 0xa7131d35, 0xbc031f59, 0x5c545ef7, 0x4ac02433,
        0x47e3cdae, 0x413da13e, 0x35146238, 0x018e0e32, 0xfa3cd245, 0x22b3ab26,
        0xaf89a0ec, 0xb7a5c5da, 0x09fe75e8, 0x57613bce, 0x330f8b1e, 0x00835129,
        0xeb8ebb13, 0x4a620943, 0xdf46066e, 0xf13f2bd7, 0x9ea9e256, 0xea6b4e2d,
        0xd1500e60, 0x5846ecbd, 0x1964e978, 0x18796f9a, 0x71093db5, 0xcc7f34f4,
        0xe333bfb1, 0x9b7c5c50, 0xa2f83019, 0x352cc045, 0x8a3ffea0, 0xd0f58bca,
        0x8f99e8f1, 0xecac4739, 0xfc671399, 0x81306c15, 0x711bd91b, 0x9081b8d7,
        0xdd578fcb, 0x0ec41250, 0x060efdfc, 0x28db027d, 0x37f37151, 0xeb56ec26,
        0x326c23ed, 0xf7c32b9c, 0x9c11ee5b, 0xf419e4be, 0x40fae05a, 0x9ba58693,
        0x5638e4bb, 0xdb6bc0e9, 0x332c6e15, 0x0009a19e, 0xb5af55db, 0x1401945e,
        0x8c192664, 0xac7a7235, 0xd2cd0b58, 0x48387de9, 0xfd6703a0, 0x7362cb7b,
        0x1cc644af, 0x8a3d3a29, 0x0e2bae7b, 0x47278f39, 0x3f203a7a, 0x5910427b,
        0xf82a2704, 0xd2f8a2cb, 0x15482a33, 0xe182eaca, 0x00c8781e, 0x7f23822a,
        0xa595328d, 0x727c67d4, 0x3e8605ee, 0x14de66be, 0x0be4ba89, 0xb7d04d9b,
        0x72f1e11e, 0x4ed78aab, 0x69746198, 0x3944dcb9, 0xf8e199f3, 0xb1e7663e,
        0xedf50b64, 0x819370bc, 0x0fe9004d, 0xc4164611, 0x48102da3, 0xb1db7357,
        0xd08c1e3d, 0x4f28f551, 0xd3561993, 0x29d9da35, 0x911c93fa, 0xcaaef82a,
        0x9705fe49, 0x2b8acfe2, 0xafaaf801, 0xbfcf73b8, 0x15bfad24, 0xfdd9b41e,
        0x3c0bd749, 0x96e5b3eb, 0x987ba72c, 0xb99b8c38, 0x54937f4d, 0xc81ba1bd,
        0x75070cca, 0xacd998c0, 0xbb2464f8, 0x3b5bac55, 0xdc5f1e41, 0x90b162fb,
        0xc210a156, 0xd8987506, 0x20d39c75, 0x4a9a4813, 0xe8a2c6b2, 0x910f4bbe,
        0x2ee18500, 0xc91c1dd9, 0xba84f016, 0xeeeec8bd, 0x49c7a28b, 0xdc0a416f,
        0x6e39d298, 0x1b558c97, 0xe856e9bb, 0x36cf58d2, 0x4dcc85bc, 0x0522418d,
        0xe4c8657c, 0x31808d72, 0xf4cc787b, 0x6be51f89, 0xb3ea9632, 0x1c017820,
        0x472757ae, 0x24f97eab, 0xd1112d9d, 0x55dfee5d, 0xf2af56ae, 0x8385be85,
        0xb36f09c3, 0xaf087659, 0xabcbe435, 0xd3bc18b0, 0x76526be6, 0xb5ef461d,
        0xbf2d9d13, 0xe5487abb, 0x9a436bcf, 0x08d62030, 0xb9842348, 0x68c2cebc,
        0xd536e1ed, 0x5941918f, 0x32de3114, 0xaf0dd940, 0x830bf357, 0x069e9efa,
        0x55724f75, 0x8c0ce92d, 0x123d7b91, 0xd1c758df, 0x81c0f120, 0x9b138a10,
        0x8d6cfcb8, 0x7d6f7e5f, 0x3ebef170, 0x383a9495, 0x6b95caad, 0xf26c980e,
        0x276889b7, 0x2f9d66ad, 0x2743b2e2, 0x151faca7, 0x6166d6fd, 0xd4bae121,
        0x4c1f045f, 0x82ed770a, 0x2da45b9e, 0x31a56faf, 0x756ac1ea, 0x79104bc4,
        0x71a8ad9a, 0x70057d3b, 0x30afdefb, 0xb58d05e3, 0x02aba334, 0x02f6de56,
        0x07163cb4, 0x9b688ead, 0x6037804f, 0x070115f1, 0x6f6b4313, 0x07308789,
        0x74f56ca3, 0x57ee2cba, 0x3f692b63, 0x474795b5, 0x1f8040ee, 0x52db461b,
        0xbac7bdfb, 0x570abeb8, 0x68edddf3, 0xd472828b, 0x17b125e7, 0x1effdf05,
        0x87e2022b, 0x8972188d, 0x96e6263a, 0xc96e2842, 0x1a4a4bb5, 0xc2b0a82f,
        0xe3f19315, 0x379429b3, 0x907ec5c7, 0x7d6d79da, 0xe3bfbffe, 0x566f9934,
        0x60aeff12, 0x9e9d17a2, 0x512eedaa, 0x04b637a0, 0x0d104851, 0xfe3ecd93,
        0xee5c42f5, 0x48099889, 0x3f87881f, 0xdd27b34a, 0x93c23d0b, 0xef7ed9aa,
        0xfefd66a2, 0xdb045a32, 0x40c4e3e0, 0xa806a218, 0xcdaa12c3, 0x2454988f,
        0xe188d563, 0x05fd89b9, 0xa5b4dcdd, 0x13996e31, 0x9b90e8cf, 0x1a827ab1,
        0xbfe44003, 0x05bfcdb6, 0x11a2a6ce, 0x4fb36a4e, 0xfad996ef, 0x439b9d76,
        0x5e31c5d0, 0xaf00cb30, 0x6e4d75df, 0xb5ddc492, 0x185a40dd, 0xa58183ee,
        0x9269a53d, 0x82b2ce5a, 0xc19def44, 0x2c9fda71, 0x891b010d, 0x6b08c436,
        0x80b21fa2, 0x6ac7e807, 0x414f21e6, 0x88c3fef9, 0xd202986c, 0x582bfd60,
        0x41b24d9a, 0x0a2b8fef, 0x4ed9e8e7, 0x49e0d38b, 0x120efd4a, 0x5edf6cad,
        0x5aec20e4, 0x6e7bd300, 0xe3f49493, 0x4aeaf53a, 0x5bc45393, 0x8a7479fe,
        0x246ac596, 0x655fa08b, 0x81fe2b29, 0x3fb1c372, 0xe810c324, 0x6097b28b,
        0x5f3b177a, 0xcd80ecf8, 0x21158e90, 0xe65de05b, 0x8c136801, 0xf035138b,
        0xfd8e574f, 0x1c956e90, 0x71571f8c, 0xdcb6da0b, 0x896128c6, 0x7b19134c,
        0x46dcd078, 0xf48f604b, 0x7701cf4f, 0x2840bae6, 0x95db993d, 0x00659c15,
        0x29b25409, 0x9dbb8edb, 0x1a19c1f4, 0x19d63b64, 0x62ee9b0c, 0x33f78c0d,
        0xfefe6a23, 0xfc0fe787, 0x885de030, 0xf13a3105, 0x6cc3d52d, 0x81488728,
        0xb5e18ea7, 0x13febf8e, 0x077dfc0d, 0x09a32301, 0x0a4f7fa7, 0x7f265384,
        0x29e6f4fc, 0x6684cd59, 0x58ede585, 0xb2c0b862, 0x24692ff9, 0xa9f92f44,
        0x102e8ed6, 0x0de534fd, 0x6d1866bf, 0xe4aae602, 0x8b7cd1e3, 0x2e5c9b72,
        0x37c2fe32, 0x993517a5, 0x2ad6c314, 0xf3b387d1, 0xad05f7b7, 0xe0b32535,
        0xf5a891c6, 0x9641f60c, 0x9bcf32ff, 0x3b7a5b4a, 0xf78b2c61, 0x795e1136,
        0xf936231e, 0x6866d465, 0x1450891f, 0x82572dc4, 0x35a2e464, 0x118153ba,
        0x845f8400, 0x5b455fd2, 0xb131e4c0, 0x68ec076f, 0xc5fcfc14, 0xbe9c3485,
        0x2e618db1, 0x9e2f204d, 0x9d620a6a, 0x78a41397, 0xb718de6f, 0x56b93ce4,
        0xf800e1f8, 0xa1098a4e, 0x04e720db, 0x21ca9ead, 0x2321543e, 0x75cf8b8f,
        0x4c42b32e, 0xb9edb96b, 0x1a385d8d, 0x15514028, 0x7b66ecf1, 0x22161cc9,
        0x4ee852af, 0xce9ffd96, 0x1cfbc12a, 0x636948b5, 0xb4d1e6d9, 0xa186da30,
        0x105dd4f9, 0x3b39bb13, 0x74863866, 0x52907f0c, 0x02883dbf, 0x503eb830,
        0xcc507232, 0x24482aec, 0xe43dd359, 0x285ff206, 0xec4c84a7, 0xb0636df8,
        0xa1488120, 0xd14c1ffb, 0xa39cc1cf, 0x138ead25, 0x41e43b80, 0x6fa765e8,
        0x34d64060, 0xbc8ff37c, 0x3eb8a24e, 0x40a3f88a, 0x5e92b113, 0x6df39364,
        0x7e271eb1, 0x5daed332, 0x029d8df7, 0x52575c7f, 0x6e43641b, 0x9028a50f,
        0x718f7fc3, 0xee037488, 0x4d4e361e, 0x545f4a00, 0xa6080b75, 0xed50c3b8,
        0x579f3c51, 0xaf69075a, 0x22c03443, 0x87bc4be6, 0x9dd4b85e, 0x227cf706,
        0x5255ee2d, 0x18a84a95, 0x1109d4f4, 0xc3f69031, 0x2d2ac862, 0xd6ba7ebb,
        0x213b4c3f, 0x8b73d3e3, 0x488b1128, 0xb6957368, 0x2ceeee9e, 0xe2db2e9f,
        0x0a8280f5, 0xccafa97b, 0xa756578a, 0x2a3ae2c7, 0x0945d579, 0xd94472a0,
        0x3e218525, 0x67678f04, 0x7728a676, 0x4c6bffae, 0x4fa7217b, 0xe39d4c36,
        0xf4866b5e, 0xa65473ec, 0x0d78373d, 0xd99c9b6d, 0x0171a33c, 0x5b83322c,
        0x4edf1e2f, 0x30d9c8d5, 0xb47b00f0, 0xc5a97931, 0xd74714d7, 0x46b7ac86,
        0xd8220f7a, 0xa8d6aa97, 0xd2658090, 0x51553797, 0xe545ba89, 0x45253aeb,
        0x94923a24, 0x3d7e3414, 0xf06da8c2, 0x69c9aa62, 0x4e1da945, 0x7e480fe5,
        0x847d4981, 0x118ffb75, 0xd8c61930, 0x7c1cd106, 0x70d04a3a, 0xeede7a65,
        0x7f59a689, 0x3dc7bffb, 0xdd020bf4, 0x72294e39, 0x54e7904c, 0x3ab730f6,
        0x77ab9d73, 0x5bbce6b7, 0x75b689ae, 0x772b799a, 0x23c03c31, 0x8d101a48,
        0xa2f044c8, 0xd2a5c05a, 0x8e2b6bfe, 0xe0366ba9, 0x61443700, 0x59f99841,
        0xc9aa6df1, 0xf905e8fb, 0x95a6e50a, 0x623b14f2, 0xc22efcce, 0xd1faacf0,
        0x7d0bd86d, 0x25faba41, 0x9035b669, 0x84e8ef05, 0x31e6f2a4, 0x42966ce2,
        0x3d31e201, 0x403d231f, 0xfc3e1d1d, 0xb40aff63, 0x81585a3c, 0x1a49d1e1,
        0xd232847a, 0xd9e24ba6, 0xf7ec01f9, 0x1558a126, 0xb2fbf233, 0xe1709723,
        0xed2d122f, 0xec972610, 0xd4658071, 0x0b641120, 0x15a1e582, 0xaf458d89,
        0xdb484bae, 0xbb7d473e, 0x5baf18cd, 0xfeb6fe7d, 0xdabac234, 0xb98ab4e0,
        0xe595c648, 0x5179f700, 0x9670816d, 0xb9a97dae, 0x1977a5cc, 0x00b6037d,
        0xd7be392b, 0x344d7db2, 0x7d9b88a5, 0xc3634f52, 0xb13aa59a, 0x030511d8,
        0x5ee48d51, 0xba4557ca, 0xea5e2bf9, 0xcb660e5d, 0xe4cced63, 0x97d47848,
        0xcd6440b7, 0x0e554823, 0xbc6cc53a, 0x22eaae49, 0xd7105dd0, 0xcc35c561,
        0x9804622b, 0x6d16d9b4, 0x392d571b, 0xa1bfece1, 0xca8ef0b2, 0xf45fc4da,
        0x04c2ccfd, 0xc96bc5c4, 0xfed406d0, 0x1a95159b, 0x7fc53162, 0x02f68387,
        0x0502bb64, 0x1c9db80e, 0x308ff221, 0xc5d2db36, 0x360ec557, 0x1afc549a,
        0xb2410acd, 0x20e3729a, 0xe310c678, 0x21d05fc9, 0x44143b32, 0xa96ca939,
        0x000c33c5, 0x381cdecc, 0xfd19370e, 0xbe8065af, 0x06f9d5e0, 0x78455f15,
        0x7bd96324, 0x2c17a7c3, 0x18165591, 0x2908c8ca, 0xf391ae9b, 0x51e85445,
        0xc150ac70, 0xfd826103, 0x0c61ce44, 0x7380e3d4, 0x8ff174b7, 0x0042a366,
        0x330da4ec, 0xcec2b1f0, 0xb1d34062, 0xc19393d0, 0xdf6d188c, 0x3f761789,
        0x19b20a83, 0x227d0157, 0x7dc22769, 0x85ed5c0f, 0xbeba3631, 0x102dc8c5,
        0x23eca378, 0xaefdd569, 0x6586c577, 0x1d5c0c97, 0x388e6d62, 0x7ab382be,
        0x5297d6a9, 0x29080a5c, 0x2ae3cf97, 0x144240c6, 0xd667f0c2, 0x3a86ca09,
        0xaf26ae5c, 0xc5a2662b, 0x3964ab36, 0xc9496505, 0x8ea69041, 0x62a82b97,
        0x435c2ed6, 0x34930891, 0xc71f2b5f, 0x9b03ae83, 0xd125c378, 0x32c281b8,
        0xe1c1bbbc, 0xba90e05c, 0x2be5753e, 0x5332849e, 0xb38fb189, 0xe6c87e38,
        0x5f1f7443, 0xaafeddd7, 0xf43dd497, 0xca166aa9, 0x40bef04e, 0xb86b78fc,
        0x666a09de, 0xf69f51b5, 0xdfbf1d7d, 0xf19ffb3f, 0x2545eab1, 0x17578311,
        0xa197f6df, 0xee616db9, 0x6c67e847, 0x85892797, 0x9d32423f, 0x1ddbab1b,
        0x580148dc, 0x15525466, 0x9eca6548, 0x338717ae, 0x4d79252c, 0x662a6b79,
        0x8ad33805, 0x223a82d0, 0x2e8d1bce, 0x62750d9c, 0x8c5d504b, 0xcfdcee61,
        0x3764306c, 0xbe07a7ca, 0xe8ea2501, 0x755cb408, 0xefdf583e, 0xdfb17d34,
        0x7cf50f34, 0xc72e6e21, 0xdef83e65, 0xa8685265, 0x0d0385c2, 0x7d87dc90,
        0x9185c3a2, 0x4fc6c0a7, 0x89a0f0e9, 0xd33bf4f0, 0x8a6297a4, 0xbd66ad75,
        0x476da766, 0x464e3a86, 0xc6f0aae9, 0xc9bcf793, 0xec014c63, 0xecc82c84,
        0xc33cd25f, 0x8f0dfcd3, 0xc5842c9e, 0x81556a5c, 0x1f85e7b0, 0x29cf42fd,
        0xd6d3bac5, 0x3edf1544, 0x5615006d, 0xd789b837, 0x9efc79a4, 0xb608d134,
        0x5b397798, 0xd58ae97b, 0x7d49f72a, 0x0faf9439, 0xb44feb46, 0xaf2ca184,
        0x1882fdf8, 0xc7ea9f1a, 0x8786b48f, 0x15078335, 0xc0f8cc03, 0x52bc9036,
        0x21ed045c, 0x99c1d442, 0x760d3349, 0x958a1fe4, 0x2296814e, 0x6b341c88,
        0x51df8432, 0xb9c19981, 0xbd126e93, 0xe15db8f0, 0x2c368aad, 0xaa83f95f,
        0x29318dcd, 0x3d2e50f3, 0xfae10193, 0xbc909861, 0xef55397b, 0x422678bd,
        0x5c81a4a7, 0x3b1b5b7f, 0x5d1ae889, 0x5c2fff73, 0x321e2b8b, 0xd4a7445e,
        0xae5c5e57, 0x326afc14, 0x3b55fbd3, 0x98034755, 0xf1225ccc, 0x5a239f86,
        0x954ab3ae, 0xdd55a628, 0x53ad4ba3, 0x2738b8f1, 0x100a963c, 0x3597965f,
        0x41a73784, 0x2d769e8b, 0x59cf3e84, 0x619c7936, 0x2aef7536, 0x9590d157,
        0x8de8976e, 0xe3a733aa, 0x46171c5e, 0x3cb43f87, 0x61da5a34, 0x79508027,
        0xceee156c, 0x23d6d8da, 0x830981fa, 0xe2aaf276, 0x0436b20a, 0x365ae355,
        0xee49396b, 0x6f50c356, 0x18ebd8ed, 0xdabb58be, 0x5cc1f991, 0x8fa2008e,
        0xa29fa632, 0x141979c0, 0xe33f7ad9, 0xa2878d88, 0xe8969a0c, 0x96ee1b8c,
        0xac34f73a, 0x14354df6, 0x121d7f63, 0x49baa849, 0x03b085b1, 0x94a33b33,
        0xb02e99a9, 0x21866af8, 0x9f964784, 0xb061430a, 0x53102548, 0x87ddd58c,
        0x5999d30d, 0xa58bd521, 0x0012e0e9, 0x566202ea, 0xb0e90b54, 0xe09e29e5,
        0x57e966ac, 0x8ad7c4dd, 0x155148a2, 0x960a1497, 0x71870c0f, 0x84616de7,
        0x9cac5f3b, 0x67406f4f, 0x3c5f9df8, 0x77df8153, 0x45a0ec5d, 0xfd1627ee,
        0xf1679028, 0x019aafc7, 0x0b6dee0f, 0x25786503, 0xf8cd0ef6, 0x1c26e69b,
        0xb9f43299, 0x345c8317, 0xe94ac354, 0x331fc77d, 0x74a1de07, 0xd90c6fb8,
        0x73a3b074, 0x7fb7ff04, 0x627efe21, 0x7db208f0, 0xfefa0584, 0x7dabe580,
        0x01f8bfeb, 0xcdd54418, 0x4a5616c2, 0xed3197e3, 0x89ac8ff6, 0xda549b85,
        0x1ab6c334, 0xa553b033, 0x0e03d3e7, 0xb2a151dd, 0x63f6ddc1, 0xdf77270e,
        0x029a938f, 0x1ad43519, 0x319c2c6c, 0x10c58b35, 0xa3b18519, 0x9c8588d5,
        0x3cb4a48d, 0x11550be1, 0x29a80750, 0x14af1b64, 0x5ff8f1a3, 0xa0e3a60b,
        0x3d7d4e36, 0xaf443239, 0xc5fbd7eb, 0x2db42d74, 0xc68b1e6e, 0x6cd93630,
        0x37e5ef89, 0x3129c91b, 0xa7432242, 0x1f5f0399, 0xb741effa, 0x0fa84ddb,
        0x142241af, 0xa5fa1176, 0x24366a31, 0x91c71609, 0x3c7fb16b, 0x25f68ebd,
        0x6dc9e596, 0xb172d768, 0xa09da221, 0xf4748b14, 0x02870198, 0xab754a7e,
        0x1fe22653, 0x36bd908c, 0xfdfd488b, 0xf501ef80, 0x4696c69a, 0xcbfb855a,
        0xb323c26a, 0x837d5b10, 0x4b211c33, 0x32bca696, 0x5e2d7eda, 0xb1565009,
        0x7c6e6a24, 0x324d84da, 0x9e3eb6c1, 0x46578ce9, 0x0930d101, 0xcd403841,
        0x0fa84f1a, 0x3f465bcf, 0x1086addb, 0x7c483c28, 0x6d6fc3c6, 0x87bf59fa,
        0xcf0e9c83, 0x8c723d99, 0x4ded357f, 0xe3c89f20, 0x109f9de5, 0xb1d2537a,
        0x23aa4b7d, 0x653e2158, 0x967ee92f, 0xe3048bca, 0x7e935db6, 0x269cf32c,
        0xf5c28b60, 0xf7f092f1, 0x07fd1b12, 0x18444395, 0x9f24b901, 0xb5ed69d3,
        0x47d25d07, 0x266d633f, 0x0f533380, 0x4584d729, 0xf0974fd7, 0x20cafa9c,
        0xd13180bc, 0x267a02a7, 0xd619719c, 0xabd81fbf, 0xcc120c38, 0xab211a9b,
        0x8a44cfc2, 0x882f0131, 0xa0181bc9, 0xd2307144, 0x05ed026e, 0x458530a0,
        0x1ed83467, 0x086acf47, 0x367d530b, 0x5bf7cfa7, 0x5dc039ae, 0x8967faf9,
        0xafe5b01e, 0x23cb3702, 0x76f39fc5, 0x41ad47f9, 0x01fa50b4, 0x79f8c6c9,
        0xd9ed623e, 0x08c81e8e, 0x9a9a6590, 0x07acc758, 0xf5a98905, 0x84fd5c8b,
        0xec34f509, 0xf298d3b7, 0x055c09a1, 0x2b7feea5, 0xa38a7301, 0xa947c000,
        0x54857d66, 0x6da6e2a6, 0x09d7e678, 0x2d72aab7, 0x802bc0d5, 0x6dd3ad26,
        0xd107d665, 0x9d85289c, 0x89395298, 0xf186d316, 0x4f2475c7, 0x1dfda1b1,
        0xeb2e6be9, 0x6ee46edf, 0xfaa80f23, 0x76aebfe7, 0xe83d494e, 0xa9a10351,
        0xe9c031b0, 0xe36e0e93, 0x154b0dd7, 0x2c6275e2, 0xcf04e031, 0x234d5576,
        0x62f8aa2b, 0x55f1c3c3, 0xf35d1d4f, 0x8b23f5a3, 0xfcef0b3f, 0x01a270ac,
        0x67345b89, 0xf08e7a5f, 0x5c83868e, 0x9b531963, 0xb15cd0cf, 0x10802fc0,
        0xc3af568a, 0x01c9850a, 0x0cd75c16, 0xd2821be3, 0x72116fff, 0xb6f2fd49,
        0x821b8ef1, 0xb3b7aeab, 0x9c6c3a5e, 0x7ec565c9, 0x90951900, 0x014310b7,
        0x30a7086b, 0x4ffe8c39, 0xceac78c2, 0x373cfd78, 0xe78e5e18, 0xd0eade50,
        0x30cca3ea, 0xcee406a6, 0x52b7c5d1, 0xad8f5da9, 0x580c4460, 0x238ab8de,
        0x9be34234, 0x3f763868, 0xfe451d2a, 0xfc3d8fc8, 0x83ab7dec, 0x6eb27841,
        0x94fbe186, 0x9a038784, 0xc886246b, 0x8d644313, 0x1e2be441, 0x8b74ae90,
        0x1f79ee26, 0xea3fbf26, 0x577594f9, 0x0b96cfc2, 0xf28bd468, 0x4c5380ec,
        0x0a0e33a6, 0x44327d97, 0x1a21b469, 0xdaa6ed1c, 0xcfe6a675, 0x92413ff5,
        0x3777438f, 0xa27179e4, 0xf72df776, 0x32912357, 0x6a6d7d43, 0x7d7beb49,
        0xe2ac47bc, 0xa2f88581, 0xe072650e, 0xa4b5e61e, 0xc3749b5e, 0xafc98f19,
        0x2e9d7f68, 0xed592bc4, 0xf257a0b2, 0xc474ed55, 0x4bc07cc3, 0x74ff9298,
        0x44c167c9, 0x41dbba81, 0x27b82053, 0xfc257989, 0x6e540bdb, 0x652f792f,
        0x24e71118, 0xdb175d84, 0xa008ad1d, 0x2871b097, 0xad7465a0, 0xf87f60bd,
        0xe4af2888, 0x348a6bdf, 0xa3b2ad40, 0x1811e8c5, 0x956bd358, 0x3d46e3a4,
        0xf57c5c09, 0x8e6af896, 0x3b39e0b3, 0x906488d9, 0x76694b11, 0x2c32339e,
        0x05b99456, 0x35d01713, 0x698a585a, 0xd5c1ffaf, 0x78344e2e, 0xa68667ce,
        0x03be10a0, 0xb694494b, 0x111f6ed3, 0x6430ea45, 0x2046c7ae, 0x1d0d29f7,
        0xa08b72d7, 0xaa3acfe4, 0x26abf9d2, 0x5bd895c4, 0x68ee4af7, 0xffac0cb9,
        0xb557b353, 0x55bac45c, 0x90298b55, 0x11f0a896, 0xb130e89d, 0xadaf5a65,
        0x8f0495e3, 0xcec67bdf, 0xbd8d7559, 0xa23b97dd, 0xba95d692, 0x282e7cf1,
        0x655ae5d8, 0x0df10cb3, 0x0d718c96, 0x727125e1, 0x7281a951, 0xf5549438,
        0x45252d55, 0x9c8a7565, 0x8feb23a1, 0xa8f8607d, 0xf61c43bf, 0xabc8525a,
        0x89fc4d21, 0x8d437899, 0x1c539597, 0xb52eefce, 0x6e8ccd99, 0x6bfc6d73,
        0xeca340ad, 0xb63c01a3, 0x2cf0e420, 0x94ee7fd3, 0x7b757054, 0xe962cfc6,
        0xd8324f5a, 0x176871c0, 0x63fd3f62, 0x464a41e0, 0x399a4261, 0xd9438f1a,
        0x98606eb2, 0x6edad323, 0xb43879d8, 0x89530f20, 0x5044c07e, 0x8df5879b,
        0xdaeb9b3e, 0x060203d7, 0x0b40e5e1, 0x6cb6422f, 0x13e25553, 0x6be52848,
        0xa601d4f8, 0xce4354be, 0x967f4088, 0x122783d0, 0x40334f99, 0x50262162,
        0xf418017d, 0x2f4ad3d8, 0x4a069a41, 0xd0312622, 0x17623703, 0xd1280ddb,
        0x04c595fd, 0x99156487, 0x2bf0359e, 0xa3a3f34a, 0xb8fe7379, 0x95ea1692,
        0xf333fb5b, 0x219da408, 0x162bbd5f, 0x7c66469f, 0x715ced40, 0x25abbca0,
        0xa3107699, 0x94af642b, 0x26758818, 0xe99da0f8, 0x1c3d8144, 0xb14b1bfb,
        0xf8351a6e, 0x86968168, 0xe7f82b4e, 0xf629c3f9, 0x0a1ea01a, 0x3cdf2107,
        0x4b08ca7a, 0xb73721a5, 0x41679e12, 0x6740817f, 0xbb42b48f, 0x51f7c3f9,
        0xb6ec54b7, 0xae7e62ae, 0xfacbe99d, 0x2c95302b, 0xbde118cb, 0x0c3bcda0,
        0x6cca4295, 0xb7f863b8, 0xb5def5d7, 0x1fd63b2e, 0xe2f19cdb, 0x60d31e1e,
        0x83453e13, 0xf438370d, 0xcf4c1588, 0x027ac92a, 0x258eb15e, 0x96043a11,
        0x51b801b6, 0xb3599614, 0x8cfd0a33, 0x3fbf384f, 0xee0402d2, 0x77829286,
        0xf19c4fae, 0x34bc9297, 0x247ef692, 0x40b26a2e, 0x8ace141f, 0xd368f553,
        0xdca1acd9, 0x4f23efb1, 0x89aa6d28, 0x248cf1bc, 0xf5f4b641, 0x3c90af60,
        0xf6b87e52, 0x2cab987c, 0x242f91d9, 0x24351691, 0xf935a89d, 0xb9491bec,
        0xc30d5638, 0xc6d855ce, 0x5d20030e, 0x0b9cbf91, 0x484b1a8b, 0x862bbaa7,
        0xd51ca063, 0xa2703863, 0xf758958a, 0x94f7bcd4, 0xfebc38cb, 0xa606a6f9,
        0xd634e792, 0xb1ac54ec, 0xbfecc2c3, 0xf26becd7, 0xbc34b409, 0x83ba71b5,
        0xf6f781c9, 0x85ef5627, 0x2d3aa21f, 0xb7c91b3a, 0xb3b07b08, 0xa74d52a4,
        0xabb203d6, 0x6177e661, 0x26a9dd30, 0x9a30e38b, 0x2037c488, 0xadb3363d,
        0x9cf2e744, 0x8beded90, 0xd7110638, 0x850d5f9e, 0xd70fa302, 0x62647d28,
        0x1d3a8cec, 0xebddecaa, 0xfb805ee5, 0x1adff30b, 0x021a63a1, 0xb8d5a3bc,
        0xc3b28262, 0x43d23529, 0x5cc2a4d8, 0x6205cad2, 0xe982005e, 0x47e70857,
        0x8dbd62c7, 0x6599b245, 0x39e658d0, 0x8afd8e9e, 0x81809727, 0x5fcc5f81,
        0x57a58468, 0xd15074d0, 0x5bbad32a, 0x3deaa4cb, 0x3038b207, 0x2f7cc991,
        0x093e99c6, 0x978e9d09, 0x9f8345ef, 0x2f122927, 0xd149bc67, 0x6f2b2095,
        0xb1d2b6d1, 0x77116e58, 0x65d5d790, 0x9eb73434, 0x4812db1a, 0x77f4086e,
        0xac3a43c5, 0x45c63d93, 0x079aa6be, 0xf0b8a330, 0x926133a3, 0x5e0a9cc7,
        0x53f53ab0, 0x9d5e0799, 0xc1a5a294, 0x1ee74b04, 0x116932c1, 0x57fb3c31,
        0xf1313fe0, 0x7beccdaf, 0x177baa53, 0x0f73bdde, 0x99aff10c, 0x4638f7d3,
        0xf4d8ee50, 0xbeda9693, 0x7b1ec0b7, 0x8f0ea14c, 0x4adec00a, 0x7706cbdc,
        0xa12d114e, 0x5bbb82e9, 0x469358aa, 0x78720867, 0x58ab7669, 0xa1736ad5,
        0x90b79e01, 0x120c29b9, 0x9f18df90, 0xce172828, 0x957ea552, 0x6e1d41e5,
        0x43517426, 0x6d633090, 0x4d5b1902, 0x49789300, 0x892b1dfc, 0xbdac18f5,
        0xf777f6af, 0x8106cc64, 0x62871815, 0xb855c449, 0x383be87d, 0x58637bf1,
        0x84fe71ce, 0x0dfb31b8,
    }};

static uint32_t kSpxEnabled = 0;

static const sigverify_spx_config_id_t kConfig = kSigverifySpxConfigIdSha2128s;

// Domain separator for pure (not pre-hashed) mode.
static const uint8_t kSpxVerifyDomainSep[] = {
    0x00,
    0x00,
};

static void enable_spx_verify(void) { kSpxEnabled = 0; }

static void disable_spx_verify(void) { kSpxEnabled = kSigverifySpxDisabledOtp; }

uint32_t sigverify_spx_verify_enabled(lifecycle_state_t lc_state) {
  if (kSpxEnabled != kSigverifySpxDisabledOtp) {
    LOG_INFO("spx_verify is enabled");
  } else {
    LOG_INFO("spx_verify is disabled");
  }
  return kSpxEnabled;
}

static rom_error_t spx_success_to_ok_test_impl(uint32_t v, bool eq) {
  uint32_t res = sigverify_spx_success_to_ok(v);
  LOG_INFO("0x%08x -> 0x%08x", v, res);
  if ((res == kErrorOk) ^ eq) {
    LOG_ERROR("Wrong result 0x%08x for 0x%08x", res, v);
    return kErrorUnknown;
  }
  return kErrorOk;
}

static rom_error_t spx_success_to_ok_test(void) {
  bool failed = false;
  failed |=
      spx_success_to_ok_test_impl(kSigverifySpxDisabledOtp, true) != kErrorOk;
  failed |= spx_success_to_ok_test_impl(kSigverifySpxSuccess, true) != kErrorOk;
  failed |= spx_success_to_ok_test_impl(UINT32_MAX, false) != kErrorOk;
  failed |= spx_success_to_ok_test_impl(0, false) != kErrorOk;
  failed |= spx_success_to_ok_test_impl(kErrorOk, false) != kErrorOk;
  if (failed) {
    return kErrorUnknown;
  }
  return kErrorOk;
}

static rom_error_t spx_verify_impl_test(void) {
  sigverify_spx_root_t expected_root;
  sigverify_spx_root_t actual_root;
  spx_public_key_root(kPubKey.data, expected_root.data);
  rom_error_t error = spx_verify(kSignature.data, kSpxVerifyDomainSep,
                                 sizeof(kSpxVerifyDomainSep), NULL, 0, NULL, 0,
                                 (const uint8_t *)kMessage, kMessageLen,
                                 kPubKey.data, actual_root.data);
  if (memcmp(&expected_root, &actual_root, sizeof(sigverify_spx_root_t)) != 0) {
    return kErrorUnknown;
  }
  return error;
}

static rom_error_t spx_verify_disabled_bad_signature_test(void) {
  disable_spx_verify();

  uint32_t flash_exec = 0;
  uint32_t good_word = kSignature.data[0];
  kSignature.data[0] = 0;
  rom_error_t error = sigverify_spx_verify(
      &kSignature, &kPubKey, kConfig, kLcStateProd, NULL, 0, NULL, 0, &kMessage,
      kMessageLen, NULL, &flash_exec);
  kSignature.data[0] = good_word;

  if (flash_exec != kSigverifySpxSuccess) {
    LOG_ERROR("flash_exec must be 0x%08x, not 0x%08x", kSigverifySpxSuccess,
              flash_exec);
    return kErrorUnknown;
  }
  return error;
}

static rom_error_t spx_verify_disabled_good_signature_test(void) {
  disable_spx_verify();

  uint32_t flash_exec = 0;
  rom_error_t error = sigverify_spx_verify(
      &kSignature, &kPubKey, kConfig, kLcStateProd, NULL, 0, NULL, 0, &kMessage,
      kMessageLen, NULL, &flash_exec);

  if (flash_exec != kSigverifySpxSuccess) {
    LOG_ERROR("flash_exec must be 0x%08x, not 0x%08x", kSigverifySpxSuccess,
              flash_exec);
    return kErrorUnknown;
  }
  return error;
}

static rom_error_t spx_verify_enabled_bad_signature_test(void) {
  enable_spx_verify();

  uint32_t flash_exec = 0;
  uint32_t good_word = kSignature.data[0];
  kSignature.data[0] = 0;
  rom_error_t error = sigverify_spx_verify(
      &kSignature, &kPubKey, kConfig, kLcStateProd, NULL, 0, NULL, 0, &kMessage,
      kMessageLen, NULL, &flash_exec);
  kSignature.data[0] = good_word;

  if (error == kErrorOk) {
    LOG_ERROR("error should not be kErrorOk");
    return kErrorUnknown;
  }
  if (flash_exec != UINT32_MAX) {
    LOG_ERROR("flash_exec must be UINT32_MAX");
    return kErrorUnknown;
  }

  return kErrorOk;
}

static rom_error_t spx_verify_enabled_good_signature_test(void) {
  enable_spx_verify();

  uint32_t flash_exec = 0;
  rom_error_t error = sigverify_spx_verify(
      &kSignature, &kPubKey, kConfig, kLcStateProd, NULL, 0, NULL, 0, &kMessage,
      kMessageLen, NULL, &flash_exec);

  if (flash_exec != kSigverifySpxSuccess) {
    LOG_ERROR("flash_exec must be 0x%08x, not 0x%08x", kSigverifySpxSuccess,
              flash_exec);
    return kErrorUnknown;
  }
  return error;
}

OTTF_DEFINE_TEST_CONFIG();

bool test_main(void) {
  (void)kPrivKey;  // Use `kPrivKey` to avoid unused variable warning.

  status_t error = OK_STATUS();

  EXECUTE_TEST(error, spx_success_to_ok_test);
  EXECUTE_TEST(error, spx_verify_impl_test);
  EXECUTE_TEST(error, spx_verify_disabled_bad_signature_test);
  EXECUTE_TEST(error, spx_verify_disabled_good_signature_test);
  EXECUTE_TEST(error, spx_verify_enabled_bad_signature_test);
  EXECUTE_TEST(error, spx_verify_enabled_good_signature_test);

  return status_ok(error);
}
